package com.implementsfaces.dao;

import org.springframework.util.ClassUtils;
import java.util.Collection;
import java.util.List;
import com.bean.${beanname};
import com.util.PaginatedList;
import com.interfaces.dao.I${beanname}DAO;
import com.interfaces.dao.IBatisDaoUtils;
/**
 * 
 * <p>功能描述:${description}</p>
 * @author  <a href="mailto: zhuyoulong@gmail.com">zhuyoulong</a>
 * @create_date 时间格式：2008-11-4
 * @version $ Revision: 1.0
 */
@SuppressWarnings("serial")
public class ${beanname}DAOImp extends GenericDaoiBatis implements I${beanname}DAO{

	/*
	 * {beanname}dao属性注入
	 */
	private I${beanname}DAO ${objectname}DAO;
	
	/**
	 * 
	 * <p>功能描述：添加方法</p>
	 * @return
	 * @author:yourname
	 * @update:[日期YYYY-MM-DD][更改人姓名][变更描述]
	 */
	public Long doinsert${beanname}(${beanname} ${objectname}){
		try{
			return (Long)getSqlMapClientTemplate().insert("${objectname}.insert${beanname}",${objectname});
		}
		catch(Exception e){
			e.printStackTrace();
			return -1L;
		}
	}
	
	/**
	 * 
	 * <p>功能描述：删除单条或多条记录方法</p>
	 * @return
	 * @author:yourname
	 * @update:[日期YYYY-MM-DD][更改人姓名][变更描述]
	 */
	public boolean dodelete${beanname}(List ids){		
		if((Integer)getSqlMapClientTemplate().delete("${objectname}.delete${beanname}",ids)>0){
			return true;
		}		
		return false;
	}
	
	/**
	 * 
	 * <p>功能描述：修改方法</p>
	 * @return
	 * @author:yourname
	 * @update:[日期YYYY-MM-DD][更改人姓名][变更描述]
	 */
	public boolean doupdate${beanname}(${beanname} ${objectname}){		
		if(getSqlMapClientTemplate().update("${objectname}.update${beanname}",${objectname})>0)
			return true;
		else
			return false;
	}
	
	/**
	 * 
	 * <p>功能描述：分页list方法</p>
	 * @return
	 * @author:yourname
	 * @update:[日期YYYY-MM-DD][更改人姓名][变更描述]
	 */
	public PaginatedList<${beanname}> get${beanname}List(${beanname} ${objectname}, int pageIndex, int pageSize){
		PaginatedList paginatedArrayList = this.getPageList(${objectname}, pageIndex, pageSize);
        ${objectname}.setStartPos(paginatedArrayList.getStartPos());
        ${objectname}.setEndPos(paginatedArrayList.getEndPos());
        paginatedArrayList.addAll(this.getList(${objectname}));
        return paginatedArrayList;
	}
	
	public List get${beanname}s(${beanname} ${objectname}){
		return getSqlMapClientTemplate().queryForList("${objectname}.get${beanname}s", ${objectname});
	}
	
	public ${beanname} get${beanname}(${beanname} ${objectname}){
		return  (${beanname})getSqlMapClientTemplate().queryForObject("${objectname}.get${beanname}", ${objectname});
	}
	
	public I${beanname}DAO get${beanname}DAO() {
		return ${objectname}DAO;
	}

	public void set${beanname}DAO(I${beanname}DAO ${objectname}DAO) {
		this.${objectname}DAO = ${objectname}DAO;
	}
	
	//分页统计,本方法为私有方法
    private int get${beanname}Count(${beanname} ${objectname}) {
        return (Integer) getSqlMapClientTemplate().queryForObject("${objectname}.get${beanname}Count", ${objectname});

    }
    
    private Collection getList(Object obj){
		
		return getSqlMapClientTemplate().queryForList(getPackage()+IBatisDaoUtils.getObjectList(ClassUtils.getShortName(obj.getClass())), obj);
	}

}
